<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>

<!--{hook index_start.htm}-->
<!-- <div class="Alert Alert--undefined ">
    <div class="container">
        <span class="Alert-body">网站改版中……</span>
    </div>
</div> -->
<div class="IndexPage">
    <header class="Hero WelcomeHero alert alert-dismissible fade show login-banner d-sm-none d-md-none d-lg-none d-xl-block" role="alert">
        <div class="container">
            <btn class="close Hero-close btn btn--icon btn-link hasIcon" type="btn" data-dismiss="alert" aria-label="关闭">
                <i class="icon fa fa-times btn-icon"></i>
            </btn>
            <div class="description text-left">
                <h1 class="title">xiǎo zhòng</h1>
                <p class="desc">只被少数人接受的爱好，名气不等于优秀，优秀不等于适合。</p>
            </div>
        </div>
    </header>
    <div class="container">
        <div class="sideNavContainer IndexPage">
            <div class="IndexPage-results sideNavOffset">
                <div class="IndexPage-toolbar">
                    <!-- 最新帖与精华帖 -->
                    <ul class="IndexPage-toolbar-view">
                        <li class="item-sort">
                            <div class="btn-group Dropdown dropdown">
                                <btn class="Dropdown-toggle btn" data-toggle="dropdown" aria-expanded="false">
                                    <span class="btn-label"><?php echo $active == 'default' ? '最新' : '精华';?></span>
                                    <i class="icon fa fa-caret-down btn-caret"></i>
                                </btn>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a href="./<?php echo url("$route");?>" class=" hasIcon" role="btn" title="<?php echo lang('new_thread');?>">
                                            <?php echo $active == 'default' ? '<i class="icon fa fa-check btn-icon"></i>' : '';?>
                                            <span class="btn-label"><?php echo lang('new_thread');?></span>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="<?php echo url("$route-0-1");?>" class="hasIcon" role="btn" title="<?php echo lang('digest_thread');?>">
                                            <?php echo $active == 'digest' ? '<i class="icon fa fa-check btn-icon"></i>' : '';?>
                                            <span class="btn-label"><?php echo lang('digest_thread');?></span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </li>
                    </ul>
                    <ul class="IndexPage-toolbar-action">
                        <?php include _include(APP_PATH.'view/htm/thread_list_mod.inc.htm');?>
                        <li class="item-refresh">
                            <btn class="btn btn--icon hasIcon win-refresh" type="btn" title="刷新" data-toggle="tooltip">
                                <i class="icon fa fa-fw fa-refresh btn-icon"></i>
                            </btn>
                        </li>
                    </ul>
                </div>
                <div class="DiscussionList">
                    <ul class="DiscussionList-discussions threadlist" id="threadlist">
                        <!--{hook index_threadlist_before.htm}-->
                        <?php include _include(APP_PATH.'view/htm/thread_list.inc.htm');?>
                        <!--{hook index_threadlist_after.htm}-->
                    </ul>
                    <div class="DiscussionList-loadMore">
                        <!--{hook index_page_before.htm}-->
                        <nav aria-label="页面导航">
                            <ul class="pagination justify-content-center flex-wrap">
                                <?php echo $pagination; ?>
                            </ul>
                        </nav>
                        <!--{hook index_page_end.htm}-->
                    </div>
                </div>
            </div>
            <nav class="IndexPage-nav sideNav">
                <ul>
                    <li class="item-newDiscussion App-primaryControl">
                    <?php if(empty($uid)) { ?>
                        <a href="<?php echo url('thread-create-'.$fid);?>" class="btn btn-primary hasIcon" role="btn" title="<?php echo lang('thread_create_new');?>">
                            <i class="icon fa fa-edit btn-icon"></i>
                            <span class="btn-label">登录后发帖</span>
                        </a>
                    <?php } else { ?>
                        <btn class="btn btn-primary hasIcon js-show" type="btn" title="<?php echo lang('thread_create_new');?>">
                            <i class="icon fa fa-edit btn-icon"></i>
                            <span class="btn-label">发新帖</span>
                        </btn>
                    <?php } ?>
                        <!--{hook index_site_brief_before.htm}-->
                    </li>
                    <li class="item-nav">
                        <div class="btnGroup Dropdown dropdown App-titleControl Dropdown--select">
                            <btn class="Dropdown-toggle btn" data-toggle="dropdown">
                                <span class="btn-label">所有话题</span>
                                <i class="icon fa fa-sort btn-caret"></i>
                            </btn>
                            <ul class="dropdown-menu">
                                <li class="item-allDiscussions active">
                                    <a href="." active="true" class=" hasIcon" type="btn" title="All Discussions">
                                        <i class="icon fa fa-fw fa-comments-o btn-icon"></i>
                                        <span class="btn-label">所有话题</span>
                                    </a>
                                </li>
                                <li class="item-following">
                                    <a href="###following" active="false" class=" hasIcon" type="btn" title="Following">
                                        <i class="icon fa fa-fw fa-star btn-icon"></i>
                                        <span class="btn-label">关注</span>
                                    </a>
                                </li>
                                <li class="item-tags">
                                    <a href="###tags" active="false" class=" hasIcon" type="btn" title="Tags">
                                        <i class="icon fa fa-fw fa-th-large btn-icon"></i>
                                        <span class="btn-label">分类</span>
                                    </a>
                                </li>
                                <li class="Dropdown-separator"></li>
                                <?php foreach($forumlist_show as $_forum) { ?>
                                <li fid="<?php echo $_forum['fid'];?>" data-active="fid-<?php echo $_forum['fid'];?>">
                                    <a class="TagLinkbtn hasIcon tags-<?php echo $_forum['fid'];?>" href="<?php echo url("forum-$_forum[fid]");?>">
                                        <span class="icon TagIcon btn-icon"></span><?php echo $_forum['name'];?>
                                    </a>
                                </li>
                                <?php } ?>
                                <!-- <li class="item-moreTags">
                                    <a href="###tags" active="false" type="btn" title="更多">
                                        <span class="btn-label">More...</span>
                                    </a>
                                </li> -->
                            </ul>
                        </div>
                    </li>
                    <li class="Dropdown-separator"></li>
                    <li class="friends-link f-13 d-sm-none d-md-none d-lg-block">
                        <p>
                            Powered by <a href="http://bbs.xiuno.com/" target="_blank" class="text-muted">Xiuno BBS <?php echo $conf['version'];?></a>
                        </p>
                        <p><a class="text-muted" href="http://www.miitbeian.gov.cn/" target="_blank">鲁ICP备10000572号-6</a></p>
                    </li>
                </ul>
            </nav>
        </div>
    </div>
</div>

<!-- 弹出的发新帖框 -->
<?php
    $form_title = lang('thread_create');
    $form_action = url("thread-create");
    $form_submit_txt = lang('thread_create');
    $form_subject = '';
    $form_message = '';
    $form_doctype = 1;
    $isfirst = 1;
    $quotepid = 0;
    $location = url("forum-'+jfid.checked()+'");
    $filelist = array();
    $filelist += (array)_SESSION('tmp_files');
    // 修改post页面新建主题时doctype的格式，0：html，1：text，2：markdown，3：ubb
    if($route == 'thread'||$route=='post' && $action == 'create') {
        $form_doctype = 0;
    }
?>

<div class="App-composer">
    <div class="container">
        <div id="composer">
            <div class="Composer normal visible active" id="js-block" style="display: none; bottom: 0px; height: 540px;">
                <div class="Composer-handle"></div>
                <ul class="Composer-controls">
                    <li class="item-minimize App-backControl">
                        <btn type="btn" class="btn btn--icon btn-link hasIcon js-hide" data-toggle="tooltip" title="最小化">
                            <i class="icon fa fa-fw fa-minus minimize btn-icon"></i>
                        </btn>
                    </li>
                    <!-- <li class="item-fullScreen">
                        <btn title="最大化" class="btn btn--icon btn-link hasIcon" type="btn">
                            <i class="icon fa fa-expand btn-icon"></i>
                        </btn>
                    </li> -->
                    <li class="item-close">
                        <btn type="btn" class="btn btn--icon btn-link hasIcon js-hide" data-toggle="tooltip" title="关闭">
                            <i class="icon fa fa-fw fa-times btn-icon"></i>
                        </btn>
                    </li>
                </ul>
                <div class="Composer-content">
                    <div class="ComposerBody ComposerBody--discussion">
                        <img class="Avatar ComposerBody-avatar" src="<?php echo $user['avatar_url'];?>">
                        <div class="ComposerBody-content">
                            <form action="<?php echo $form_action;?>" method="post" id="form">
                                <input type="hidden" name="doctype" value="0">
                                <ul class="ComposerBody-header">
                                    <li class="item-title"><h3>新的话题</h3></li>
                                    <li class="item-tags mr-3">
                                        <select class="custom-select w-auto" name="fid">
                                            <?php foreach ($forumlist_show as $_forum) { ?>
                                            <option value="<?php echo $_forum['fid']; ?>"><?php echo $_forum['name']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </li>
                                    <li class="item-discussionTitle">
                                        <h3><input class="form-control comments-input" placeholder="<?php echo lang('subject');?>" name="subject" value="" id="subject" autofocus="autofocus"></h3>
                                    </li>
                                </ul>
                                <div class="ComposerBody-editor">
                                    <div class="TextEditor">
                                        <div class="ComposerBody-emojiWrapper">
                                            <div class="ComposerBody-mentionsWrapper">
                                                <textarea class="form-control Composer-flexible" placeholder="<?php echo lang('message');?>" name="message" id="message" style="height: 426px; background-color: #fff;"><?php echo $form_message;?></textarea>
                                            </div>
                                        </div>
                                        <ul class="TextEditor-controls Composer-footer">
                                            <li class="item-submit App-primaryControl">
                                                <btn class="btn btn-primary hasIcon" type="submit" id="submit" data-loading-text="<?php echo lang('submiting');?>...">
                                                    <i class="icon fa fa-check btn-icon"></i>
                                                    <span class="btn-label"><?php echo $form_submit_txt;?></span>
                                                </btn>
                                            </li>
                                            <li>
                                                <a class="btn" href="<?php echo url('thread-create-'.$fid);?>">
                                                    <span>全屏编辑</span>
                                                </a>
                                            </li>
                                            <li>
                                                <!--{hook post_message_after.htm}-->
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--{hook index_end.htm}-->

<?php include _include(APP_PATH.'view/htm/footer.inc.htm');?>
<link href="plugin/xn_umeditor/umeditor/themes/default/css/umeditor.css<?php echo $static_version;?>" rel="stylesheet">
<link href="plugin/xn_umeditor/umeditor/umeditor-bbs.css<?php echo $static_version;?>" rel="stylesheet" />
<script src="plugin/xn_umeditor/umeditor/umeditor.config.js<?php echo $static_version;?>"></script>
<script src="plugin/xn_umeditor/umeditor/umeditor.js<?php echo $static_version;?>"></script>
<script src="plugin/xn_umeditor/umeditor/umeditor-insertcode.js<?php echo $static_version;?>"></script>
<script src="plugin/xn_umeditor/umeditor/umeditor-bbs.js<?php echo $static_version;?>"></script>
<script src="plugin/xn_umeditor/umeditor/lang/zh-cn/zh-cn.js<?php echo $static_version;?>"></script>
<script>
$('li[data-active="fid-0"]').addClass('active');
// 百度编辑器
var xn_sbform=$('#message').parents('form'); //获取文本框message所在form表单
xn_sbform.on('submit',function(){UM.getEditor('message').sync();}); //给submit挂载同步事件
var xn_sbdata=$._data(xn_sbform[0],'events').submit; //获取form表单submit事件列表
xn_sbdata.splice(0,0,xn_sbdata.pop()); //把同步事件优先级设到最前
// 发表话题
var jform = $('#form');
var jsubmit = $('#submit');
var jfid = jform.find('select[name="fid"]');
jform.on('submit', function() {
    jform.reset();
    jsubmit.btn('loading');
    var postdata = jform.serialize();
    $.xpost(jform.attr('action'), postdata, function(code, message) {
        if(code == 0) {
            $.alert(message);
            jsubmit.btn(message).delay(1000).location('<?php echo $location;?>');
        } else if(xn.is_number(code)) {
            alert(message);
            jsubmit.btn('reset');
        } else {
            $.alert(message);
            //jform.find('[name="'+code+'"]').alert(message).focus();
            jsubmit.btn('reset');
        }
    });
    return false;
});

var jattachparent = $('.attachlist_parent');
$('#addattach').on('change', function(e) {
    var files = xn.get_files_from_event(e);
    if (!files) return;

    // 并发下会 服务端 session 写入会有问题，由客户端控制改为串行
    if (!jattachparent.find('.attachlist').length) {
        jattachparent.append('<fieldset class="fieldset"><legend><?php echo lang('uploaded_attach');?></legend><ul class="attachlist"><ul></fieldset>');
    }

    var jprogress = jattachparent.find('.progress');
    if(!jprogress.length) {
        jprogress = $('<div class="progress"><div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">25%</div></div>').appendTo(jattachparent);
    }
    jprogressbar = jprogress.find('.progress-bar');

    $.each_sync(files, function(i, callback) {
        var file = files[i];
        xn.upload_file(file, xn.url('attach-create'), {is_image: 0}, function(code, message) {
            if (code != 0) return $.alert(message);
            // 把文件 append 到附件列表
            var url = message.url;
            var filetype = message.filetype;
            var aid = message.aid;
            $('.attachlist').append('<li aid="' + aid + '"><a href="' + message.url + '" target="_blank"><i class="icon filetype ' + filetype + '"></i> ' + message.orgfilename + '</a> <a href="javascript:void(0);" class="delete ml-2"><i class="fa fa-remove"></i> <?php echo lang('delete');?></a></li>');
            callback();
            jprogress.hide();
        }, function(percent) {
            percent = xn.intval(percent);
            jprogressbar.css('width', percent+'%');
            jprogressbar.text(percent+'%');
            jprogress.show();
            console.log('progress:'+ percent);
        });
    });
});

// 删除附件
jattachparent.on('click', 'a.delete', function() {
    var jlink = $(this);
    var jli = jlink.parents('li');
    var aid = jli.attr('aid');
    if(!window.confirm(lang.confirm_delete)) return false;
    $.xpost(xn.url('attach-delete-'+aid), function(code, message) {
        if(code != 0) return $.alert(message);
        jlink.parent().remove();
    });
    return false;
})

jform.find('[name="fid"]').checked(<?php echo $fid;?>);

</script>

<!--{hook index_js.htm}-->